﻿using System;
using System.Diagnostics;
using Seagull.Configuration;

namespace Seagull.DAL.Utils
{
    [DebuggerDisplay("{ToString()}")]
    public class FrameDataNoiseFilter : FrameDataCoercer
    {
        /// <summary>
        /// 噪声阈值
        /// </summary>
        private readonly double _noiseQuota;

        private readonly byte _defaultValue;

        public FrameDataNoiseFilter(double noiseQuota, byte defaultValue)
        {
            _noiseQuota = noiseQuota;
            _defaultValue = defaultValue;
        }

        public override void Coerce(byte[] frameData)
        {
            for(int i = 0; i < frameData.Length; i++)
            {
                if(frameData[i] < _noiseQuota)
                {
                    frameData[i] = _defaultValue;
                }
            }
        }

        public override string ToString()
        {
            return string.Format("NoiseQuota: {0}", _noiseQuota);
        }
    }
}
